package com.icinfo.cloud.provider.punish.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.DocumentKindEnum;
import com.icinfo.cloud.provider.common.page.PageResponse;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.HeaderUtil;
import com.icinfo.cloud.provider.exception.BusinessException;
import com.icinfo.cloud.provider.punish.approval.dto.*;
import com.icinfo.cloud.provider.punish.approval.vo.*;
import com.icinfo.cloud.provider.punish.fastcase.service.IFastCaseService;
import com.icinfo.cloud.provider.punish.fastcase.vo.AppFastCaseSendDocumentVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastAutoCloseCaseReminderVo;
import com.icinfo.cloud.provider.punish.fastcase.vo.FastCaseButtonVo;
import com.icinfo.cloud.provider.punish.mapper.*;
import com.icinfo.cloud.provider.punish.service.ApprovalService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseDocumentRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseIllegalParkingRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseIllegalParkingRecordRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseProgramTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseStageEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseBasicInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseIllegalParkingRecordVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseReasonEntrustVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.model.CaseCollectiveDiscuss;
import com.icinfo.cloud.provider.punish.vo.CaseInfoVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 审批相关实现
 *
 * @author Administrator
 */
@Service
@Slf4j
public class ApprovalServiceImpl implements ApprovalService {

    @Resource
    CasePartiesRecordMapper casePartiesRecordMapper;
    @Resource
    CasePartiesPersonInfoMapper casePartiesPersonInfoMapper;
    @Resource
    CasePartiesLegalInfoMapper casePartiesLegalInfoMapper;
    @Resource
    CaseHandlePersonRecordMapper caseHandlePersonRecordMapper;
    @Value("${tzService.url}")
    private String url;
    @Resource
    private CaseMainInfoMapper caseMainInfoMapper;
    @Resource
    private CaseReasonMainRecordMapper caseReasonMainRecordMapper;
    @Resource
    private CaseCollectiveDiscussMapper caseCollectiveDiscussMapper;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;

    @Resource
    private IFastCaseService fastCaseService;

    @Override
    public Result<AuditInfoVo> getAuditDocDetail(AuditDetailDocumentQueryDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("audit/getAuditDocDetail")).addHeaders(headers).body(param).execute().body();
        Result<AuditInfoVo> result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result<PageResponse<AuditInfoListVo>> getWaitAuditList(AuditQueryPageDto auditQueryPageDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        //移动端排除修改文书的审批记录
        auditQueryPageDto.setIsQueryEditRecord("0");
        String param = JSON.toJSONString(auditQueryPageDto);
        String response = HttpUtil.createPost(url.concat("waitAudit/getWaitAuditList")).addHeaders(headers).body(param).execute().body();
        Result<PageResponse<AuditInfoListVo>> result = JSON.parseObject(response, Result.class);
        return result;

    }

    @Override
    public Result doAgreeAudit(ApprovalAgreeAuditDto approvalAuditDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(approvalAuditDto);
        String response = HttpUtil.createPost(url.concat("waitAudit/doAgreeAudit")).addHeaders(headers).body(param).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result doReturnAudit(ApprovalReturnlAuditDto approvalAuditDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(approvalAuditDto);
        String response = HttpUtil.createPost(url.concat("waitAudit/doReturnAudit")).addHeaders(headers).body(param).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result<List<AuditInfoChainLogVo>> getAuditChain(AuditDetailDocumentQueryDto auditDetailDocumentQueryDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(auditDetailDocumentQueryDto);
        String response = HttpUtil.createPost(url.concat("audit/getAuditChain")).addHeaders(headers).body(param).execute().body();
        Result<List<AuditInfoChainLogVo>> result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result<AuditInfoChainLogTopVo> getAuditChainTop(AuditDetailDocumentQueryDto auditDetailDocumentQueryDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(auditDetailDocumentQueryDto);
        String response = HttpUtil.createPost(url.concat("audit/getAuditChainTop")).addHeaders(headers).body(param).execute().body();
        Result<AuditInfoChainLogTopVo> result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result<CaseBasicInfoVo> getCaseBasicInfo(String caseId) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        JSONObject json = new JSONObject();
        json.put("caseId", caseId);
        String response = HttpUtil.createPost(url.concat("/punish/ucase/case/main/getCaseDetailInfo")).addHeaders(headers).body(json.toJSONString()).execute().body();
        Result<CaseBasicInfoVo> result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result<PageResponse<AuditInfoListVo>> getOffAuditList(AuditQueryPageDto auditQueryPageDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(auditQueryPageDto);
        String response = HttpUtil.createPost(url.concat("audit/getOffAuditList")).addHeaders(headers).body(param).execute().body();
        Result<PageResponse<AuditInfoListVo>> result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result<List<NextAuditUserVo>> getNextNodeUser(AuditNextUserQueryDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String param = JSON.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("waitAudit/getNextNodeUser")).addHeaders(headers).body(param).execute().body();
        Result<List<NextAuditUserVo>> result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 获取案件基础信息--案件详情
     *
     * @param caseId
     * @return CaseInfoVo
     * @author lxj
     */
    @Override
    public CaseInfoVo getCaseInfo(String caseId) {

        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
        if (caseMainInfo == null) {
            throw new BusinessException("未找到案件信息");
        }
        CaseInfoVo vo = new CaseInfoVo();
        //1.将主表信息放入返回视图里面
        vo.setCaseId(caseMainInfo.getId());
        BeanUtils.copyProperties(caseMainInfo, vo);
        //2.办案人员信息
        Example handleExample = new Example(CaseHandlePersonRecord.class);
        handleExample.createCriteria().andEqualTo("caseId", caseId);
        handleExample.setOrderByClause("handle_person_type asc");
        List<CaseHandlePersonRecord> caseHandlePersonRecordList = caseHandlePersonRecordMapper.selectByExample(handleExample);
        if (caseHandlePersonRecordList.size() > 0) {
            vo.setCaseHandlingDeptInfo(caseHandlePersonRecordList.get(0).getHandleDeptName());
            vo.setCaseHandlePersonList(caseHandlePersonRecordList);
        } else {
            throw new BusinessException("未匹配到办案人员记录");
        }
        //3.获取当事人信息
        Example queryExample = new Example(CasePartiesRecord.class);
        queryExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", "1");
        List<CasePartiesRecord> casePartiesRecord = casePartiesRecordMapper.selectByExample(queryExample);
        if (ObjectUtils.isEmpty(casePartiesRecord)) {
            throw new BusinessException("未找到当事人信息");
        }
        String partyType = casePartiesRecord.get(0).getPartyType();
        vo.setPartyTypeName(PartyTypeEnum.getValueByCode(partyType));
        if (PartyTypeEnum.PERSON.getCode().equals(partyType)) {
            CasePartiesPersonInfo casePartiesPersonInfo = casePartiesPersonInfoMapper.selectByPrimaryKey(casePartiesRecord.get(0).getPartyId());
            if (ObjectUtils.isEmpty(casePartiesPersonInfo)) {
                throw new BusinessException("未找到当事人个人信息");
            }
            vo.setCasePartiesPersonInfo(casePartiesPersonInfo);
        } else {
            CasePartiesLegalInfo casePartiesLegalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(casePartiesRecord.get(0).getPartyId());
            if (ObjectUtils.isEmpty(casePartiesLegalInfo)) {
                throw new BusinessException("未找到当事人法人信息");
            }
            vo.setCasePartiesLegalInfo(casePartiesLegalInfo);
        }
        //4. 案由
        Example example = new Example(CaseReasonMainRecord.class);
        example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", "1");
        List<CaseReasonMainRecord> caseReasonMainRecordList = caseReasonMainRecordMapper.selectByExample(example);
        //案由没有就不显示
//        if (ObjectUtils.isEmpty(caseReasonMainRecordList) || caseReasonMainRecordList.size() == 0) {
//            throw new BusinessException("未匹配到案件案由记录");
//        }

        vo.setCaseTypeCode(vo.getCaseType());
        vo.setCaseType(CaseTypeEnum.getValueByCode(vo.getCaseType()));
        //快办流程设置为普通程序
        if (CaseTypeEnum.SIMPLE_QUICK.getCode().equals(vo.getCaseTypeCode())) {
            vo.setCaseType(CaseTypeEnum.NORMAL_PROCEDURE.getDes());
        }
        //设置程序类型名称
        vo.setCaseProgramTypeName(CaseProgramTypeEnum.getValueByCode(vo.getCaseTypeCode()));

        //查询是否为线上集体议案
        Example collectiveDiscussExample = new Example(CaseCollectiveDiscuss.class);
        collectiveDiscussExample.createCriteria().andEqualTo("caseId", caseId)
                .andEqualTo("discussMethod", Constant.STRING_2);
        List<CaseCollectiveDiscuss> caseCollectiveDiscussList = caseCollectiveDiscussMapper.selectByExample(collectiveDiscussExample);
        if (CollectionUtils.isNotEmpty(caseCollectiveDiscussList)) {
            CaseCollectiveDiscuss discuss = caseCollectiveDiscussList.get(0);
            vo.setCollectiveDiscuss(Constant.STRING_2);
            if (StringUtils.isNotBlank(discuss.getDocumentCatalogCode())) {
                Example collectiveDiscussDocumentExample = new Example(CaseDocumentRecord.class);
                collectiveDiscussDocumentExample.createCriteria().andEqualTo("caseId", caseId)
                        .andEqualTo("documentCatalogCode", discuss.getDocumentCatalogCode());
                List<CaseDocumentRecord> collectiveDiscussDocuments = caseDocumentRecordMapper.selectByExample(collectiveDiscussDocumentExample);
                if (CollectionUtils.isNotEmpty(collectiveDiscussDocuments)) {
                    vo.setCollectiveDiscussDocumentUrl(collectiveDiscussDocuments.get(0).getDocumentUrl());
                }
            }
        }
        /*if (Constant.STRING_1.equals(vo.getCaseType())) {
            vo.setCaseType("简易程序");
        } else if (Constant.STRING_2.equals(vo.getCaseType())) {
            vo.setCaseType("一般程序");
        }else if (Constant.STRING_3.equals(vo.getCaseType())) {
            vo.setCaseType("快速办理");
        }*/
        //计算剩余时间
        handleRemainTimes(vo);
        //fixme:目前只考虑案件单案由
        if (!ObjectUtils.isEmpty(caseReasonMainRecordList) || caseReasonMainRecordList.size() > 0) {
            CaseReasonMainRecord record = caseReasonMainRecordList.get(Constant.INTEGER_0);
            vo.setCaseReasonCode(record.getCaseReasonCode());
            vo.setCaseReasonName(record.getCaseReasonNameSimple());
        }
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        if (ObjectUtil.isNotEmpty(caseMainDetailInfo)) {
            vo.setPunishOpinion(caseMainDetailInfo.getPunishOpinion());
            vo.setInvestConclusion(caseMainDetailInfo.getInvestConclusion());
        }
        //省简案快办自动结案提醒处理
        if (CaseTypeEnum.FAST_PROCEDURE.getCode().equals(caseMainInfo.getCaseType())
                && CaseStageEnum.PUNISH_EXECUTION.getCode().equals(caseMainInfo.getCaseCurrentStageCode())) {
            //只有执行阶段才会触发自动结案提醒
            FastAutoCloseCaseReminderVo autoCloseCaseReminder = fastCaseService.getAutoCloseCaseReminder(caseId);
            vo.setFastAutoCloseCaseReminderVo(autoCloseCaseReminder);
        }
        //简案快办按钮控制处理
        dealFastCaseButtonList(vo);
        //简案快办需送达的文书处理
        dealFastCaseSendDocument(vo);
        //处理委托执法信息
        dealEntrustCaseInfo(vo);
        return vo;
    }

    /**
     * 处理委托执法信息
     *
     * @param vo
     */
    private void dealEntrustCaseInfo(CaseInfoVo vo) {
        //不为简易程序则不处理
        if (!CaseTypeEnum.SIMPLE_PROCEDURE.getCode().equals(vo.getCaseType())) {
            return;
        }
        //查询案由案件记录
        CaseReasonMainRecord caseRecord = new CaseReasonMainRecord();
        caseRecord.setCaseId(vo.getCaseId());
        //找到委托案件 4->委托案件
        caseRecord.setSxType("4");
        List<CaseReasonMainRecord> records = caseReasonMainRecordMapper.select(caseRecord);
        if (CollUtil.isEmpty(records)) {
            return;
        }
        //存在委托事项
        vo.setHadEntrustCase(true);
        vo.setEntrustReasonList(records.stream().map(CaseReasonEntrustVo::new).collect(Collectors.toList()));
    }

    /**
     * 简案快办按钮控制处理
     *
     * @param vo
     */
    private void dealFastCaseButtonList(CaseInfoVo vo) {
        if (!CaseTypeEnum.FAST_PROCEDURE.getCode().equals(vo.getCaseTypeCode())) {
            return;
        }
        List<FastCaseButtonVo> fastCaseButtonList = new ArrayList<>();
        String caseCurrentStageName = vo.getCaseCurrentStageName();
        String caseCurrentLinkName = vo.getCaseCurrentLinkName();
        //立案
        if (CaseStageEnum.CASE_REGISTER.getDes().equals(caseCurrentStageName)
                || "暂存".equals(caseCurrentStageName)) {
            FastCaseButtonVo supplement = new FastCaseButtonVo("supplement", "继续补充");
            fastCaseButtonList.add(supplement);
        } else if ("处罚告知".equals(caseCurrentLinkName)
                || "不予处罚告知".equals(caseCurrentLinkName)) {
            FastCaseButtonVo supplement = new FastCaseButtonVo("supplement", "继续补充");
            FastCaseButtonVo mergeSubmit = new FastCaseButtonVo("mergeSubmit", "提交审批");
            fastCaseButtonList.add(supplement);
            fastCaseButtonList.add(mergeSubmit);
        } else if ("处罚告知送达".equals(caseCurrentLinkName) || "不予处罚告知送达".equals(caseCurrentLinkName)
                || "处罚决定送达".equals(caseCurrentLinkName) || "不予处罚决定送达".equals(caseCurrentLinkName)) {
            FastCaseButtonVo send = new FastCaseButtonVo("send", "电子送达");
            fastCaseButtonList.add(send);
        } else if ("放弃陈述申辩".equals(caseCurrentLinkName)) {
            FastCaseButtonVo waiverPlea = new FastCaseButtonVo("waiverPlea", "放弃陈述申辩");
            fastCaseButtonList.add(waiverPlea);
        } else if ("处罚决定".equals(caseCurrentLinkName) || "不予处罚决定".equals(caseCurrentLinkName)) {
            FastCaseButtonVo decide = new FastCaseButtonVo("decide", "处罚决定");
            fastCaseButtonList.add(decide);
        } else if ("处罚执行".equals(caseCurrentLinkName)) {
            FastCaseButtonVo execute = new FastCaseButtonVo("execute", "执行情况");
            fastCaseButtonList.add(execute);
        } else if ("结案".equals(caseCurrentLinkName)) {
            FastCaseButtonVo closeCase = new FastCaseButtonVo("closeCase", "结案归档");
            fastCaseButtonList.add(closeCase);
        }
        vo.setFastCaseButtonList(fastCaseButtonList);
    }

    /**
     * 简案快办需送达的文书处理
     *
     * @param vo
     */
    private void dealFastCaseSendDocument(CaseInfoVo vo) {
        if (!CaseTypeEnum.FAST_PROCEDURE.getCode().equals(vo.getCaseTypeCode())) {
            return;
        }
        String caseId = vo.getCaseId();
        String caseCurrentLinkName = vo.getCaseCurrentLinkName();
        String documentKindCode = null;
        if ("处罚告知送达".equals(caseCurrentLinkName)) {
            documentKindCode = DocumentKindEnum.DOC_KIND_CFGZS.getCode();
        } else if ("不予处罚告知送达".equals(caseCurrentLinkName)) {
            documentKindCode = DocumentKindEnum.DOC_KIND_DK2BYXZCFGZS.getCode();
        } else if ("处罚决定送达".equals(caseCurrentLinkName)) {
            documentKindCode = DocumentKindEnum.DOC_KIND_CFJDS.getCode();
        } else if ("不予处罚决定送达".equals(caseCurrentLinkName)) {
            documentKindCode = DocumentKindEnum.DOC_KIND_BYCFJDS.getCode();
        } else {
            return;
        }

        CaseDocumentRecordDto recordDto = caseDocumentRecordMapper.selectCaseDocumentRecordByKindCode(caseId, documentKindCode);
        if (ObjectUtil.isNotEmpty(recordDto)) {
            AppFastCaseSendDocumentVo caseSendDocumentVo = new AppFastCaseSendDocumentVo();
            BeanUtils.copyProperties(recordDto, caseSendDocumentVo);
            caseSendDocumentVo.setDocumentId(recordDto.getId());
            vo.setFastCaseSendDocument(caseSendDocumentVo);
        }
    }

    /**
     * 获取审批相关状态
     *
     * @param
     * @return {@link ApprovalInfoVo}
     * @author liyafeng
     * @date 2022/8/9
     */
    @Override
    public Result getApprovalInfo(ApprovalQueryDto approvalQueryDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(approvalQueryDto);
        String response = HttpUtil.createPost(url.concat("waitAudit/getApprovalInfo")).addHeaders(headers).body(json).execute().body();
        Result<ApprovalInfoVo> result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 提交审批
     *
     * @param dto
     * @return {@link Result}
     * @author liyafeng
     * @date 2022/12/13
     */
    @Override
    public Result documentGeneralSubmit(ApprovalGeneralSubmitDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("waitAudit/documentGeneralSubmit")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 提交自动审批
     *
     * @param dto
     * @return {@link Result}
     * @author liyafeng
     * @date 2022/12/14
     */
    @Override
    public Result documentGeneralSubmitAuto(ApprovalGeneralSubmitDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("waitAudit/documentGeneralSubmitAuto")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 速结程序查询当前审批信息
     *
     * @param dto
     * @return {@link Result< FastCaseApprovalInfoVo>}
     * @author liyafeng
     * @date 2022/12/14
     */
    @Override
    public Result<FastCaseApprovalInfoVo> getFastCaseApprovalInfo(FastCaseApprovalDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("waitAudit/getFastCaseApprovalInfo")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 获取机动车违停记录列表
     *
     * @param request
     * @return
     */
    @Override
    public Result<PageResponse<CaseIllegalParkingRecordVo>> getIllegalParkingList(CaseIllegalParkingRecordRequest request) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(request);
        String response = HttpUtil.createPost(url.concat("punish/ucase/case/illegalParking/getIllegalParkingList")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 新增机动车违停记录
     *
     * @param dto
     * @return
     */
    @Override
    public Result saveIllegalParkingRecord(CaseIllegalParkingRecordDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("punish/ucase/case/illegalParking/saveIllegalParkingRecord")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 修改机动车违停记录
     *
     * @param dto
     * @return
     */
    @Override
    public Result updateIllegalParkingRecord(CaseIllegalParkingRecordDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("punish/ucase/case/illegalParking/updateIllegalParkingRecord")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 删除机动车违停记录
     *
     * @param dto
     * @return
     */
    @Override
    public Result deleteIllegalParkingRecord(CaseIllegalParkingRecordDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("punish/ucase/case/illegalParking/deleteIllegalParkingRecord")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 获取机动车违停记录详情
     *
     * @param dto
     * @return
     */
    @Override
    public Result<CaseIllegalParkingRecordVo> getIllegalParkingRecordDetail(CaseIllegalParkingRecordDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("punish/ucase/case/illegalParking/getIllegalParkingRecordDetail")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 速结程序查询是否审批完成
     *
     * @param dto
     * @return {@link Result< FastCaseApprovalInfoVo>}
     * @author liyafeng
     * @date 2023/1/3
     */
    @Override
    public Result<String> getFastCaseIsApprovalPass(FastCaseApprovalDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("waitAudit/getFastCaseIsApprovalPass")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 合并提交审批接口，该文书需要审批调用（简案快办合并提交使用）
     *
     * @param dto
     * @return {@link Result}
     * @author liyafeng
     * @date 2023/5/10
     */
    @Override
    public Result documentGeneralMergeSubmit(ApprovalGeneralSubmitDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("waitAudit/documentGeneralMergeSubmit")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 审批通过（合并审批）
     *
     * @param approvalAuditDto
     * @return {@link Result}
     * @author liyafeng
     * @date 2023/5/10
     */
    @Override
    public Result doAgreeAuditMerge(ApprovalAgreeAuditDto approvalAuditDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(approvalAuditDto);
        String response = HttpUtil.createPost(url.concat("waitAudit/doAgreeAuditMerge")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    /**
     * 审批退回(合并审批)
     *
     * @param approvalAuditDto
     * @return {@link Result}
     * @author liyafeng
     * @date 2023/5/10
     */
    @Override
    public Result doReturnAuditMerge(ApprovalReturnlAuditDto approvalAuditDto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(approvalAuditDto);
        String response = HttpUtil.createPost(url.concat("waitAudit/doReturnAuditMerge")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }

    @Override
    public Result getApprovalOpinionHis(ApprovalOpinionHisQueryDto dto) {
        Map<String, String> headers = HeaderUtil.headerInfo();
        String json = JSONObject.toJSONString(dto);
        String response = HttpUtil.createPost(url.concat("audit/getApprovalOpinionHis")).addHeaders(headers).body(json).execute().body();
        Result result = JSON.parseObject(response, Result.class);
        return result;
    }


    /**
     * 计算超出时间--办案日期，裁决完毕日期
     *
     * @param vo
     * @return void
     * @author lxj
     * @date 2022/3/1
     **/
    private void handleRemainTimes(CaseInfoVo vo) {
        if (vo.getCaseTimelimit() == null) {
            return;
        }
        int timeLimit = BaseUtil.getBetweenDays(BaseUtil.getTodayStartDate(), BaseUtil.localDateToDate(vo.getCaseTimelimit()));
        //办案期限
        //裁决期限 如果裁决日期不等于空，说明已经裁决，不计算案件到期时间和裁决期限
        if (vo.getCaseVerdictEndTime() == null) {
            if (timeLimit == Constant.INTEGER_0) {
                vo.setRemainTime("已到期");
            } else if (timeLimit > Constant.INTEGER_0) {
                vo.setRemainTime("剩余" + timeLimit + "天");
            } else {
                vo.setRemainTime("超" + String.valueOf(timeLimit).substring(Constant.INTEGER_1) + "天");
            }
            vo.setRemainVerdictTime(vo.getRemainTime());
        }
    }

}
